package org.datascooter.db.mysql;

import java.sql.SQLException;

import javax.sql.ConnectionPoolDataSource;

import org.datascooter.impl.ContextConnector;
import org.datascooter.inface.IDataSource;

import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource;

public class MysqlConnector extends ContextConnector {

	public MysqlConnector() {
	}

	public MysqlConnector(IDataSource source) throws SQLException {
		super(source);
	}

	@Override
	public ConnectionPoolDataSource createPooledDataSource() throws SQLException {
		if (source == null) {
			MysqlConnectionPoolDataSource jDBCdataSource = new MysqlConnectionPoolDataSource();
			jDBCdataSource.setURL(dataSource.getURL());
			jDBCdataSource.setUser(dataSource.getUser());
			jDBCdataSource.setPassword(dataSource.getPassword());
			return jDBCdataSource;
		}
		return source;
	}

	@Override
	public String getContextId() {
		return "mysql";
	}
}
